package Demo3_9;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User：Lenovo
 * Date:2025-03-09
 * Time:21:51
 */
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // 读取 N 和 M
        int N = sc.nextInt();
        int M = sc.nextInt();

        // 读取铠甲勇士的能量值
        List<Long> energyList = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            energyList.add(sc.nextLong());
        }

        // 读取暗影护法的战斗力
        long[] B = new long[M];
        for (int i = 0; i < M; i++) {
            B[i] = sc.nextLong();
        }

        // 计算结果
        ArmorWarriors solver = new ArmorWarriors(energyList);
        StringBuilder result = new StringBuilder();
        for (long b : B) {
            result.append(solver.minCombination(b)).append(" ");
        }

        // 输出结果
        System.out.println(result.toString().trim());
    }
}

class ArmorWarriors {
    private List<Long> filteredEnergy;

    public ArmorWarriors(List<Long> energyList) {
        this.filteredEnergy = filterEnergy(energyList);
    }

    // 过滤掉能被其他能量整除的冗余能量值
    private List<Long> filterEnergy(List<Long> energyList) {
        TreeSet<Long> sortedSet = new TreeSet<>(energyList);
        List<Long> uniqueEnergy = new ArrayList<>(sortedSet);
        List<Long> filtered = new ArrayList<>();

        for (int i = 0; i < uniqueEnergy.size(); i++) {
            boolean isUseful = true;
            for (int j = 0; j < i; j++) {
                if (uniqueEnergy.get(i) % uniqueEnergy.get(j) == 0) {
                    isUseful = false;
                    break;
                }
            }
            if (isUseful) {
                filtered.add(uniqueEnergy.get(i));
            }
        }
        return filtered;
    }

    // 使用 BFS 计算最少的铠甲勇士合体数
    public int minCombination(long target) {
        Queue<long[]> queue = new LinkedList<>();
        Set<Long> visited = new HashSet<>();

        queue.offer(new long[]{0, 0}); // {当前能量和，使用的个数}
        visited.add(0L);

        while (!queue.isEmpty()) {
            long[] curr = queue.poll();
            long sum = curr[0];
            int count = (int) curr[1];

            if (sum == target) {
                return count;
            }

            for (long energy : filteredEnergy) {
                long newSum = sum + energy;
                if (newSum <= target && !visited.contains(newSum)) {
                    queue.offer(new long[]{newSum, count + 1});
                    visited.add(newSum);
                }
            }
        }
        return -1; // 无法合成
    }
}
